<%- include header %>
<!-- page content -->
<div class="right_col" role="main">

    <div class="">
        <div class="page-title">
        </div>
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <ul class="breadcrumb">
                            <li>
                                <a href="/admin/index">
                                    <i class="fa fa-home"></i>&nbsp;首页&nbsp;
                                </a>
                            </li>
                            <li class="active">
                                <i class="fa fa-photo"></i>&nbsp;像框管理&nbsp;
                            </li>
                            <li>
                                <a href="/admin/frame/list">
                                    像框列表
                                </a>
                            </li>
                            <li class="active">
                                修改像框
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                    	<div class="col-md-4 col-sm-4 col-xs-12 animated fadeInDown">
                            <div class="well profile_view">
                                <div class="col-sm-12">
                                        <img style="width:262.5px;height: 422.1px;" id="imgUpload" src="<%= frame.url %>">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                            <div class="x_content">
                                <br />
                                <div class="form-horizontal form-label-left">
                                	<div class="form-group">
		                                <label class="control-label col-md-3 col-sm-3 col-xs-12">图片上传</label>
		                                <div class="col-md-9 col-sm-9 col-xs-12">
		                                    <form action="https://www.zxzhai.cn/v1/tools/upload/img/weapp" method="post" enctype="multipart/form-data" style="margin-top: -9px;">
                                                <div class="weui_uploader_input_wrp">
                                                    <div style="text-align: center">
                                                        <i class="fa fa-plus" style="font-size:2em;color:#beb9b9;margin-top: 1em;">
                                                        </i>
                                                    </div>
                                                    <input id="imgFile" name='usr_file' class="weui_uploader_input" type="file" accept="image/jpg,image/jpeg,image/png,image/gif" multiple="" onchange="imgFileInput()">
                                                </div>
                                            </form>
		                                </div>
			                        </div>
                                    <div class="form-group">
                                        <div class="form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12">排序序号</label>
                                            <div class="col-md-9 col-sm-9 col-xs-12">
                                                <input type="text" class="form-control" placeholder="请输入排序序号，数字越大越靠前" id="btnIndexNum" value="<%= frame.indexNum || 0 %>">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                                            <!-- <button type="submit" class="btn btn-primary">Cancel</button> -->
                                            <button  class="btn btn-success" onclick="edit('<%= frame._id %>')" id="subBtn">提交</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- footer content -->
    
    <!-- /footer content -->

</div>
<!-- /page content -->
<%- include bottom %>
<script type="text/javascript" src="/js/jquery.form.js" ></script>
<script type="text/javascript">
    function edit(id) {
		var url = $('#imgUpload').attr('src');
		if(!url){
			return alert('请上传图片');
		}
        var indexNum = $('#btnIndexNum').val();
        $('#subBtn').attr('disabled','disabled');
        
    	var obj = {frame_id: id,url:url,indexNum:indexNum}
    	$.ajax({
            type: "post",
            url: "/admin/frame/edit",
            data: obj,
            dataType: "json",
            success: function(data) {
            	$('#subBtn').removeAttr('disabled');
                if(data.status==true){
                    window.location.href = '/admin/frame/list';
                }else{
                    alert(data.info);
                }
            },
            error: function(data) {
                $('#subBtn').removeAttr('disabled');
                alert(data.responseText);
            }
        });
    }

    function imgFileInput() {
        var imgFile = $('#imgFile').val();
        if(imgFile){
            var strExtension = imgFile.substr(imgFile.lastIndexOf('.') + 1);
            if (strExtension != 'jpg' && strExtension != 'png' && strExtension != 'pdf' && strExtension != 'gif') {
                alert("请选择图片格式文件");
                return;
            }
        }
        $('form').ajaxSubmit({
        	data: {'type': 'weapp_frame'},
            success: function(data){
            	console.log(data);
                if(data.status){
                    $('#imgUpload').attr('src', data.img_url);
                }else{
                    alert(data.message);
                }
            }
        });
        return false;
    }
</script>
<%- include footer %>